package com.zrrd.threadSleep;

/**
 * @author WanJl
 * @version 1.0
 * @title MyRunnable
 * @description sleep线程休眠(有时限等待)
 * @create 2024/6/16
 */
//1、定义一个类MyRunnable实现Runnable接口
public class MyRunnable implements Runnable {
    //2、在MyRunnable类中重写run()方法
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            //调用休眠的方法，让当前线程有时限的等待
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName()+"-->"+i);
        }
    }

}
